package net.csdn.business.gateway.component;

import org.springframework.context.annotation.Primary;
import org.springframework.security.authentication.ReactiveAuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

import java.util.Collection;
import java.util.Collections;

/**
 * @Auther: zhangyalei
 * @Date: 2022/12/1 19:23
 * @Description: token 认证处理
 */
/*@Component
@Primary*/
public class TokenAuthenticationManager implements ReactiveAuthenticationManager {
    @Override
    @SuppressWarnings("unchecked")
    public Mono<Authentication> authenticate(Authentication authentication) {
        return Mono.just(authentication)
                .map(auth -> {
                   // Collection<? extends GrantedAuthority> roles =  Collections.EMPTY_LIST;
                    Collection<? extends GrantedAuthority> roles =  Collections.EMPTY_LIST;
                    return new UsernamePasswordAuthenticationToken(
                            auth.getPrincipal().toString(),
                            null,
                            roles);
                });
    }
}
